home *** CD-ROM | disk | FTP | other *** search
/ PC Gamer (Italian) 48 / PC Gamer IT CD 48 2-2.iso / Starsiege / tribesdemo.exe / Disk1 / data1.cab / Tribes_Demo / base / scripts.vol / game.cs < prev    next >
Encoding:
Text File  |  1999-09-14  |  28.8 KB  |  886 lines

  1. exec("comchat.cs");
  2. $SensorNetworkEnabled = true;
  3.  
  4. $GuiModePlay = 1;
  5. $GuiModeCommand = 2;
  6. $GuiModeVictory = 3;
  7. $GuiModeInventory = 4;
  8. $GuiModeObjectives = 5;
  9. $GuiModeLobby = 6;
  10.  
  11.  
  12. //  Global Variables
  13.  
  14. //---------------------------------------------------------------------------------
  15. // Energy each team is given at beginning of game
  16. //---------------------------------------------------------------------------------
  17. $DefaultTeamEnergy = "Infinite";
  18.  
  19. //---------------------------------------------------------------------------------
  20. // Team Energy variables
  21. //---------------------------------------------------------------------------------
  22. $TeamEnergy[-1] = $DefaultTeamEnergy; 
  23. $TeamEnergy[0]  = $DefaultTeamEnergy; 
  24. $TeamEnergy[1]  = $DefaultTeamEnergy; 
  25. $TeamEnergy[2]  = $DefaultTeamEnergy; 
  26. $TeamEnergy[3]  = $DefaultTeamEnergy; 
  27. $TeamEnergy[4]  = $DefaultTeamEnergy; 
  28. $TeamEnergy[5]  = $DefaultTeamEnergy; 
  29. $TeamEnergy[6]  = $DefaultTeamEnergy;                 
  30. $TeamEnergy[7]  = $DefaultTeamEnergy; 
  31.  
  32. //---------------------------------------------------------------------------------
  33. // Time in sec player must wait before he can throw a Grenade or Mine after leaving
  34. //    a station.
  35. //---------------------------------------------------------------------------------
  36. $WaitThrowTime = 2;
  37.  
  38. //---------------------------------------------------------------------------------
  39. // If 1 then Team Spending Ignored -- Team Energy is set to $MaxTeamEnergy every
  40. //     $secTeamEnergy.
  41. //---------------------------------------------------------------------------------
  42. $TeamEnergyCheat = 0;
  43.  
  44. //---------------------------------------------------------------------------------
  45. // MAX amount team energy can reach
  46. //---------------------------------------------------------------------------------
  47. $MaxTeamEnergy = 700000;
  48.  
  49. //---------------------------------------------------------------------------------
  50. //  Time player has to put flag in flagstand before it gets returned to its last
  51. //  location. 
  52. //---------------------------------------------------------------------------------
  53. $flagToStandTime = 180;      
  54.  
  55. //---------------------------------------------------------------------------------
  56. // Amount to inc team energy every ($secTeamEnergy) seconds
  57. //---------------------------------------------------------------------------------
  58. $incTeamEnergy = 700;
  59.  
  60. //---------------------------------------------------------------------------------
  61. // (Rate is sec's) Set how often TeamEnergy is incremented
  62. //---------------------------------------------------------------------------------
  63. $secTeamEnergy = 30;
  64.  
  65. //---------------------------------------------------------------------------------
  66. // (Rate is sec's) Items respwan
  67. //---------------------------------------------------------------------------------
  68. $ItemRespawnTime = 30;
  69.  
  70. //---------------------------------------------------------------------------------
  71. //Amount of Energy remote stations start out with
  72. //---------------------------------------------------------------------------------
  73. $RemoteAmmoEnergy = 2500; 
  74. $RemoteInvEnergy = 3000;
  75.  
  76. //---------------------------------------------------------------------------------
  77. // TEAM ENERGY -  Warn team when teammate has spent x amount - Warn team that 
  78. //                  energy level is low when it reaches x amount 
  79. //---------------------------------------------------------------------------------
  80. $TeammateSpending = -4000;  //Set = to 0 if don't want the warning message
  81. $WarnEnergyLow = 4000;        //Set = to 0 if don't want the warning message
  82.  
  83. //---------------------------------------------------------------------------------
  84. // Amount added to TeamEnergy when a player joins a team
  85. //---------------------------------------------------------------------------------
  86. $InitialPlayerEnergy = 5000;
  87.  
  88. //---------------------------------------------------------------------------------
  89. // REMOTE TURRET
  90. //---------------------------------------------------------------------------------
  91. $MaxNumTurretsInBox = 2;     //Number of remote turrets allowed in the area
  92. $TurretBoxMaxLength = 50;    //Define Max Length of the area
  93. $TurretBoxMaxWidth =  50;    //Define Max Width of the area
  94. $TurretBoxMaxHeight = 25;    //Define Max Height of the area
  95.  
  96. $TurretBoxMinLength = 10;      //Define Min Length from another turret
  97. $TurretBoxMinWidth =  10;      //Define Min Width from another turret
  98. $TurretBoxMinHeight = 10;    //Define Min Height from another turret
  99.  
  100. //---------------------------------------------------------------------------------
  101. //    Object Types    
  102. //---------------------------------------------------------------------------------
  103. $SimTerrainObjectType    = 1 << 1;
  104. $SimInteriorObjectType   = 1 << 2;
  105. $SimPlayerObjectType     = 1 << 7;
  106.  
  107. $MineObjectType            = 1 << 26;    
  108. $MoveableObjectType        = 1 << 22;
  109. $VehicleObjectType          = 1 << 29;  
  110. $StaticObjectType             = 1 << 23;       
  111. $ItemObjectType             = 1 << 21;      
  112.  
  113. //---------------------------------------------------------------------------------
  114. // CHEATS
  115. //---------------------------------------------------------------------------------
  116. $ServerCheats = 0;
  117. $TestCheats = 0;
  118.  
  119. //---------------------------------------------------------------------------------
  120. //Respawn automatically after X sec's -  If 0..no respawn
  121. //---------------------------------------------------------------------------------
  122. $AutoRespawn = 0;
  123.  
  124. //---------------------------------------------------------------------------------
  125. // Player death messages - %1 = killer's name, %2 = victim's name
  126. //       %3 = killer's gender pronoun (his/her), %4 = victim's gender pronoun
  127. //---------------------------------------------------------------------------------
  128. $deathMsg[$LandingDamageType, 0]      = "%2 falls to %3 death.";
  129. $deathMsg[$LandingDamageType, 1]      = "%2 forgot to tie %3 bungie cord.";
  130. $deathMsg[$LandingDamageType, 2]      = "%2 bites the dust in a forceful manner.";
  131. $deathMsg[$LandingDamageType, 3]      = "%2 fall down go boom.";
  132. $deathMsg[$ImpactDamageType, 0]      = "%1 makes quite an impact on %2.";
  133. $deathMsg[$ImpactDamageType, 1]      = "%2 becomes the victim of a fly-by from %1.";
  134. $deathMsg[$ImpactDamageType, 2]      = "%2 leaves a nasty dent in %1's fender.";
  135. $deathMsg[$ImpactDamageType, 3]      = "%1 says, 'Hey %2, you scratched my paint job!'";
  136. $deathMsg[$BulletDamageType, 0]      = "%1 ventilates %2 with %3 chaingun.";
  137. $deathMsg[$BulletDamageType, 1]      = "%1 gives %2 an overdose of lead.";
  138. $deathMsg[$BulletDamageType, 2]      = "%1 fills %2 full of holes.";
  139. $deathMsg[$BulletDamageType, 3]      = "%1 guns down %2.";
  140. $deathMsg[$EnergyDamageType, 0]      = "%2 dies of turret trauma.";
  141. $deathMsg[$EnergyDamageType, 1]      = "%2 is chewed to pieces by a turret.";
  142. $deathMsg[$EnergyDamageType, 2]      = "%2 walks into a stream of turret fire.";
  143. $deathMsg[$EnergyDamageType, 3]      = "%2 ends up on the wrong side of a turret.";
  144. $deathMsg[$PlasmaDamageType, 0]      = "%2 feels the warm glow of %1's plasma.";
  145. $deathMsg[$PlasmaDamageType, 1]      = "%1 gives %2 a white-hot plasma injection.";
  146. $deathMsg[$PlasmaDamageType, 2]      = "%1 asks %2, 'Got plasma?'";
  147. $deathMsg[$PlasmaDamageType, 3]      = "%1 gives %2 a plasma transfusion.";
  148. $deathMsg[$ExplosionDamageType, 0]   = "%2 catches a Frisbee of Death thrown by %1.";
  149. $deathMsg[$ExplosionDamageType, 1]   = "%1 blasts %2 with a well-placed disc.";
  150. $deathMsg[$ExplosionDamageType, 2]   = "%1's spinfusor caught %2 by surprise.";
  151. $deathMsg[$ExplosionDamageType, 3]   = "%2 falls victim to %1's Stormhammer.";
  152. $deathMsg[$ShrapnelDamageType, 0]    = "%1 blows %2 up real good.";
  153. $deathMsg[$ShrapnelDamageType, 1]    = "%2 gets a taste of %1's explosive temper.";
  154. $deathMsg[$ShrapnelDamageType, 2]    = "%1 gives %2 a fatal concussion.";
  155. $deathMsg[$ShrapnelDamageType, 3]    = "%2 never saw it coming from %1.";
  156. $deathMsg[$LaserDamageType, 0]       = "%1 adds %2 to %3 list of sniper victims.";
  157. $deathMsg[$LaserDamageType, 1]       = "%1 fells %2 with a sniper shot.";
  158. $deathMsg[$LaserDamageType, 2]       = "%2 becomes a victim of %1's laser rifle.";
  159. $deathMsg[$LaserDamageType, 3]       = "%2 stayed in %1's crosshairs for too long.";
  160. $deathMsg[$MortarDamageType, 0]      = "%1 mortars %2 into oblivion.";
  161. $deathMsg[$MortarDamageType, 1]      = "%2 didn't see that last mortar from %1.";
  162. $deathMsg[$MortarDamageType, 2]      = "%1 inflicts a mortal mortar wound on %2.";
  163. $deathMsg[$MortarDamageType, 3]      = "%1's mortar takes out %2.";
  164. $deathMsg[$BlasterDamageType, 0]     = "%2 gets a blast out of %1.";
  165. $deathMsg[$BlasterDamageType, 1]     = "%2 succumbs to %1's rain of blaster fire.";
  166. $deathMsg[$BlasterDamageType, 2]     = "%1's puny blaster shows %2 a new world of pain.";
  167. $deathMsg[$BlasterDamageType, 3]     = "%2 meets %1's master blaster.";
  168. $deathMsg[$ElectricityDamageType, 0] = "%2 gets zapped with %1's ELF gun.";
  169. $deathMsg[$ElectricityDamageType, 1] = "%1 gives %2 a nasty jolt.";
  170. $deathMsg[$ElectricityDamageType, 2] = "%2 gets a real shock out of meeting %1.";
  171. $deathMsg[$ElectricityDamageType, 3] = "%1 short-circuits %2's systems.";
  172. $deathMsg[$CrushDamageType, 0]         = "%2 didn't stay away from the moving parts.";
  173. $deathMsg[$CrushDamageType, 1]         = "%2 is crushed.";
  174. $deathMsg[$CrushDamageType, 2]         = "%2 gets smushed flat.";
  175. $deathMsg[$CrushDamageType, 3]         = "%2 gets caught in the machinery.";
  176. $deathMsg[$DebrisDamageType, 0]         = "%2 is a victim among the wreckage.";
  177. $deathMsg[$DebrisDamageType, 1]         = "%2 is killed by debris.";
  178. $deathMsg[$DebrisDamageType, 2]         = "%2 becomes a victim of collateral damage.";
  179. $deathMsg[$DebrisDamageType, 3]         = "%2 got too close to the exploding stuff.";
  180. $deathMsg[$MissileDamageType, 0]        = "%2 takes a missile up the keister.";
  181. $deathMsg[$MissileDamageType, 1]        = "%2 gets shot down.";
  182. $deathMsg[$MissileDamageType, 2]        = "%2 gets real friendly with a rocket.";
  183. $deathMsg[$MissileDamageType, 3]        = "%2 feels the burn from a warhead.";
  184. $deathMsg[$MineDamageType, 0]           = "%1 blows %2 up real good.";
  185. $deathMsg[$MineDamageType, 1]           = "%2 gets a taste of %1's explosive temper.";
  186. $deathMsg[$MineDamageType, 2]           = "%1 gives %2 a fatal concussion.";
  187. $deathMsg[$MineDamageType, 3]           = "%2 never saw it coming from %1.";
  188.  
  189. // "you just killed yourself" messages
  190. //   %1 = player name,  %2 = player gender pronoun
  191.  
  192. $deathMsg[-2,0]                         = "%1 ends it all.";
  193. $deathMsg[-2,1]                         = "%1 takes %2 own life.";
  194. $deathMsg[-2,2]                         = "%1 kills %2 own dumb self.";
  195. $deathMsg[-2,3]                         = "%1 decides to see what the afterlife is like.";
  196.  
  197. $numDeathMsgs = 4;
  198. //---------------------------------------------------------------------------------
  199.  
  200. $spawnBuyList[0] = LightArmor;
  201. $spawnBuyList[1] = Blaster;
  202. $spawnBuyList[2] = Chaingun;
  203. $spawnBuyList[3] = Disclauncher;
  204. $spawnBuyList[4] = RepairKit;
  205. $spawnBuyList[5] = "";
  206.  
  207. function remotePlayMode(%clientId)
  208. {
  209.    if(!%clientId.guiLock)
  210.    {
  211.       remoteSCOM(%clientId, -1);
  212.       Client::setGuiMode(%clientId, $GuiModePlay);
  213.    }
  214. }
  215.  
  216. function remoteCommandMode(%clientId)
  217. {
  218.    // can't switch to command mode while a server menu is up
  219.    if(!%clientId.guiLock)
  220.    {
  221.       remoteSCOM(%clientId, -1);  // force the bandwidth to be full command
  222.         if(%clientId.observerMode != "pregame")
  223.            checkControlUnmount(%clientId);
  224.         Client::setGuiMode(%clientId, $GuiModeCommand);
  225.    }
  226. }
  227.  
  228. function remoteInventoryMode(%clientId)
  229. {
  230.    if(!%clientId.guiLock && !Observer::isObserver(%clientId))
  231.    {
  232.       remoteSCOM(%clientId, -1);
  233.       Client::setGuiMode(%clientId, $GuiModeInventory);
  234.    }
  235. }
  236.  
  237. function remoteObjectivesMode(%clientId)
  238. {
  239.    if(!%clientId.guiLock)
  240.    {
  241.       remoteSCOM(%clientId, -1);
  242.       Client::setGuiMode(%clientId, $GuiModeObjectives);
  243.    }
  244. }
  245.  
  246. function remoteScoresOn(%clientId)
  247. {
  248.    if(!%clientId.menuMode)
  249.       Game::menuRequest(%clientId);
  250. }
  251.  
  252. function remoteScoresOff(%clientId)
  253. {
  254.    Client::cancelMenu(%clientId);
  255. }
  256.  
  257. function remoteToggleCommandMode(%clientId)
  258. {
  259.     if (Client::getGuiMode(%clientId) != $GuiModeCommand)
  260.         remoteCommandMode(%clientId);
  261.     else
  262.         remotePlayMode(%clientId);
  263. }
  264.  
  265. function remoteToggleInventoryMode(%clientId)
  266. {
  267.     if (Client::getGuiMode(%clientId) != $GuiModeInventory)
  268.         remoteInventoryMode(%clientId);
  269.     else
  270.         remotePlayMode(%clientId);
  271. }
  272.  
  273. function remoteToggleObjectivesMode(%clientId)
  274. {
  275.     if (Client::getGuiMode(%clientId) != $GuiModeObjectives)
  276.         remoteObjectivesMode(%clientId);
  277.     else
  278.         remotePlayMode(%clientId);
  279. }
  280.  
  281. function Time::getMinutes(%simTime)
  282. {
  283.    return floor(%simTime / 60);
  284. }
  285.  
  286. function Time::getSeconds(%simTime)
  287. {
  288.    return %simTime % 60;
  289. }
  290.  
  291. function Game::pickRandomSpawn(%team)
  292. {
  293.    %group = nameToID("MissionGroup/Teams/team" @ %team @ "/DropPoints/Random");
  294.    %count = Group::objectCount(%group);
  295.    if(!%count)
  296.       return -1;
  297.       %spawnIdx = floor(getRandom() * (%count - 0.1));
  298.       %value = %count;
  299.     for(%i = %spawnIdx; %i < %value; %i++) {
  300.         %set = newObject("set",SimSet);
  301.         %obj = Group::getObject(%group, %i);
  302.         if(containerBoxFillSet(%set,$SimPlayerObjectType|$VehicleObjectType,GameBase::getPosition(%obj),2,2,4,0) == 0) {
  303.             deleteObject(%set);
  304.             return %obj;        
  305.         }
  306.         if(%i == %count - 1) {
  307.             %i = -1;
  308.             %value = %spawnIdx;
  309.         }
  310.         deleteObject(%set);
  311.     }
  312.    return false;
  313. }
  314.  
  315. function Game::pickStartSpawn(%team)
  316. {
  317.    %group = nameToID("MissionGroup\\Teams\\team" @ %team @ "\\DropPoints\\Start");
  318.    %count = Group::objectCount(%group);
  319.    if(!%count)
  320.       return -1;
  321.  
  322.    %spawnIdx = $lastTeamSpawn[%team] + 1;
  323.    if(%spawnIdx >= %count)
  324.       %spawnIdx = 0;
  325.    $lastTeamSpawn[%team] = %spawnIdx;
  326.    return Group::getObject(%group, %spawnIdx);
  327. }
  328.  
  329. function Game::pickTeamSpawn(%team, %respawn)
  330. {
  331.    if(%respawn)
  332.       return Game::pickRandomSpawn(%team);
  333.    else
  334.    {
  335.       %spawn = Game::pickStartSpawn(%team);
  336.       if(%spawn == -1)
  337.          return Game::pickRandomSpawn(%team);
  338.       return %spawn;
  339.    }
  340. }
  341.  
  342. function Game::pickObserverSpawn(%client)
  343. {
  344.    %group = nameToID("MissionGroup\\ObserverDropPoints");
  345.    %count = Group::objectCount(%group);
  346.    if(%group == -1 || !%count)
  347.       %group = nameToID("MissionGroup\\Teams\\team" @ Client::getTeam(%client) @ "\\DropPoints\\Random");
  348.    %count = Group::objectCount(%group);
  349.    if(%group == -1 || !%count)
  350.       %group = nameToID("MissionGroup\\Teams\\team0\\DropPoints\\Random");
  351.    %count = Group::objectCount(%group);
  352.    if(%group == -1 || !%count)
  353.       return -1;
  354.    %spawnIdx = %client.lastObserverSpawn + 1;
  355.    if(%spawnIdx >= %count)
  356.       %spawnIdx = 0;
  357.    %client.lastObserverSpawn = %spawnIdx;
  358.     return Group::getObject(%group, %spawnIdx);
  359. }
  360.  
  361. function UpdateClientTimes(%time)
  362. {
  363.    for(%cl = Client::getFirst(); %cl != -1; %cl = Client::getNext(%cl))
  364.       remoteEval(%cl, "setTime", -%time);
  365. }
  366.  
  367. function Game::notifyMatchStart(%time)
  368. {
  369.    messageAll(0, "Match starts in " @ %time @ " seconds.");
  370.    UpdateClientTimes(%time);
  371. }
  372.  
  373. function Game::startMatch()
  374. {
  375.    $matchStarted = true;
  376.    $missionStartTime = getSimTime();
  377.    messageAll(0, "Match started.");
  378.     Game::resetScores();    
  379.  
  380.    %numTeams = getNumTeams();
  381.    for(%i = 0; %i < %numTeams; %i = %i + 1) {
  382.         if($TeamEnergy[%i] != "Infinite")
  383.             schedule("replenishTeamEnergy(" @ %i @ ");", $secTeamEnergy);
  384.     }
  385.  
  386.    for(%cl = Client::getFirst(); %cl != -1; %cl = Client::getNext(%cl))
  387.    {
  388.         if(%cl.observerMode == "pregame")
  389.       {
  390.          %cl.observerMode = "";
  391.          Client::setControlObject(%cl, Client::getOwnedObject(%cl));
  392.       }
  393.        Game::refreshClientScore(%cl);
  394.     }
  395.    Game::checkTimeLimit();
  396. }
  397.  
  398. function Game::pickPlayerSpawn(%clientId, %respawn)
  399. {
  400.    return Game::pickTeamSpawn(Client::getTeam(%clientId), %respawn);
  401. }
  402.  
  403. function Game::playerSpawn(%clientId, %respawn)
  404. {
  405.    if(!$ghosting)
  406.       return false;
  407.  
  408.     Client::clearItemShopping(%clientId);
  409.    %spawnMarker = Game::pickPlayerSpawn(%clientId, %respawn);
  410.    if(!%respawn)
  411.    {
  412.       // initial drop
  413.       bottomprint(%clientId, "<jc><f0>Mission: <f1>" @ $missionName @ "   <f0>Mission Type: <f1>" @ $Game::missionType @ "\n<f0>Press <f1>'O'<f0> for specific objectives.", 5);
  414.    }
  415.     if(%spawnMarker) {   
  416.         %clientId.guiLock = "";
  417.          %clientId.dead = "";
  418.        if(%spawnMarker == -1)
  419.        {
  420.           %spawnPos = "0 0 300";
  421.           %spawnRot = "0 0 0";
  422.        }
  423.        else
  424.        {
  425.           %spawnPos = GameBase::getPosition(%spawnMarker);
  426.           %spawnRot = GameBase::getRotation(%spawnMarker);
  427.        }
  428.  
  429.         if(!String::ICompare(Client::getGender(%clientId), "Male"))
  430.           %armor = "larmor";
  431.        else
  432.           %armor = "lfemale";
  433.  
  434.        %pl = spawnPlayer(%armor, %spawnPos, %spawnRot);
  435.        echo("SPAWN: cl:" @ %clientId @ " pl:" @ %pl @ " marker:" @ %spawnMarker @ " armor:" @ %armor);
  436.        if(%pl != -1)
  437.        {
  438.           GameBase::setTeam(%pl, Client::getTeam(%clientId));
  439.           Client::setOwnedObject(%clientId, %pl);
  440.           Game::playerSpawned(%pl, %clientId, %armor, %respawn);
  441.           
  442.           if($matchStarted)
  443.              Client::setControlObject(%clientId, %pl);
  444.           else
  445.           {
  446.              %clientId.observerMode = "pregame";
  447.              Client::setControlObject(%clientId, Client::getObserverCamera(%clientId));
  448.              Observer::setOrbitObject(%clientId, %pl, 3, 3, 3);
  449.           }
  450.        }
  451.       return true;
  452.     }
  453.     else {
  454.         Client::sendMessage(%clientId,0,"Sorry No Respawn Positions Are Empty - Try again later ");
  455.       return false;
  456.     }
  457. }
  458.  
  459. function Game::playerSpawned(%pl, %clientId, %armor)
  460. {                          
  461.     %clientId.spawn= 1;
  462.     %max = getNumItems();
  463.    for(%i = 0; (%item = $spawnBuyList[%i]) != ""; %i++)
  464.    {
  465.         buyItem(%clientId,%item);    
  466.         if(%item.className == Weapon) 
  467.             %clientId.spawnWeapon = %item;
  468.     }
  469.     %clientId.spawn= "";
  470.     if(%clientId.spawnWeapon != "") {
  471.         Player::useItem(%pl,%clientId.spawnWeapon);    
  472.        %clientId.spawnWeapon="";
  473.     }
  474.  
  475. function Game::autoRespawn(%client)
  476. {
  477.     if(%client.dead == 1)
  478.         Game::playerSpawn(%client, "true");
  479. }
  480.  
  481. function onServerGhostAlwaysDone()
  482. {
  483. }
  484.  
  485. function Game::initialMissionDrop(%clientId)
  486. {
  487.     Client::setGuiMode(%clientId, $GuiModePlay);
  488.  
  489.    if($Server::TourneyMode)
  490.       GameBase::setTeam(%clientId, -1);
  491.    else
  492.    {
  493.       if(%clientId.observerMode == "observerFly" || %clientId.observerMode == "observerOrbit")
  494.       {
  495.           %clientId.observerMode = "observerOrbit";
  496.           %clientId.guiLock = "";
  497.          Observer::jump(%clientId);
  498.          return;
  499.       }
  500.       %numTeams = getNumTeams();
  501.       %curTeam = Client::getTeam(%clientId);
  502.  
  503.       if(%curTeam >= %numTeams || (%curTeam == -1 && (%numTeams < 2 || $Server::AutoAssignTeams)) )
  504.          Game::assignClientTeam(%clientId);
  505.    }    
  506.     Client::setControlObject(%clientId, Client::getObserverCamera(%clientId));
  507.    %camSpawn = Game::pickObserverSpawn(%clientId);
  508.    Observer::setFlyMode(%clientId, GameBase::getPosition(%camSpawn), 
  509.        GameBase::getRotation(%camSpawn), true, true);
  510.  
  511.    if(Client::getTeam(%clientId) == -1)
  512.    {
  513.       %clientId.observerMode = "pickingTeam";
  514.  
  515.       if($Server::TourneyMode && ($matchStarted || $matchStarting))
  516.       {
  517.          %clientId.observerMode = "observerFly";
  518.          return;
  519.       }
  520.       else if($Server::TourneyMode)
  521.       {
  522.          if($Server::TeamDamageScale)
  523.             %td = "ENABLED";
  524.          else
  525.             %td = "DISABLED";
  526.          bottomprint(%clientId, "<jc><f1>Server is running in Competition Mode\nPick a team.\nTeam damage is " @ %td, 0);
  527.       }
  528.       Client::buildMenu(%clientId, "Pick a team:", "InitialPickTeam");
  529.       Client::addMenuItem(%clientId, "0Observe", -2);
  530.       Client::addMenuItem(%clientId, "1Automatic", -1);
  531.       for(%i = 0; %i < getNumTeams(); %i = %i + 1)
  532.          Client::addMenuItem(%clientId, (%i+2) @ getTeamName(%i), %i);
  533.       %clientId.justConnected = "";
  534.    }
  535.    else 
  536.    {
  537.       Client::setSkin(%clientId, $Server::teamSkin[Client::getTeam(%clientId)]);
  538.       if(%clientId.justConnected)
  539.       {
  540.          centerprint(%clientId, $Server::JoinMOTD, 0);
  541.          %clientId.observerMode = "justJoined";
  542.          %clientId.justConnected = "";
  543.       }
  544.       else if(%clientId.observerMode == "justJoined")
  545.       {
  546.          centerprint(%clientId, "");
  547.          %clientId.observerMode = "";
  548.          Game::playerSpawn(%clientId, false);
  549.       }
  550.       else
  551.          Game::playerSpawn(%clientId, false);
  552.     }
  553.     if($TeamEnergy[Client::getTeam(%clientId)] != "Infinite")
  554.         $TeamEnergy[Client::getTeam(%clientId)] += $InitialPlayerEnergy;
  555.     %clientId.teamEnergy = 0;
  556. }
  557.  
  558. function processMenuInitialPickTeam(%clientId, %team)
  559. {
  560.    if($Server::TourneyMode && $matchStarted)
  561.       %team = -2;
  562.  
  563.    if(%team == -2)
  564.    {
  565.       Observer::enterObserverMode(%clientId);
  566.    }
  567.    if(%team == -1)
  568.    {
  569.       Game::assignClientTeam(%clientId);
  570.       %team = Client::getTeam(%clientId);
  571.    }
  572.    if(%team != -2)
  573.    {
  574.       GameBase::setTeam(%clientId, %team);
  575.         if($TeamEnergy[%team] != "Infinite")
  576.             $TeamEnergy[%team] += $InitialPlayerEnergy;
  577.       %clientId.teamEnergy = 0;
  578.       Client::setControlObject(%clientId, -1);
  579.       Game::playerSpawn(%clientId, false);
  580.    }
  581.    if($Server::TourneyMode && !$CountdownStarted)
  582.    {
  583.       if(%team != -2)
  584.       {
  585.          bottomprint(%clientId, "<f1><jc>Press FIRE when ready.", 0);
  586.          %clientId.notready = true;
  587.          %clientId.notreadyCount = "";
  588.       }
  589.       else
  590.       {
  591.          bottomprint(%clientId, "", 0);
  592.          %clientId.notready = "";
  593.          %clientId.notreadyCount = "";
  594.       }
  595.    }
  596. }
  597.  
  598. function Game::ForceTourneyMatchStart()
  599. {
  600.    %playerCount = 0;
  601.    for(%cl = Client::getFirst(); %cl != -1; %cl = Client::getNext(%cl))
  602.    {
  603.       if(%cl.observerMode == "pregame")
  604.          %playerCount++;
  605.    }
  606.    if(%playerCount == 0)
  607.       return;
  608.  
  609.    for(%cl = Client::getFirst(); %cl != -1; %cl = Client::getNext(%cl))
  610.    {
  611.       if(%cl.observerMode == "pickingTeam")   
  612.          processMenuInitialPickTeam(%cl, -2); // throw these guys into observer
  613.       for(%cl = Client::getFirst(); %cl != -1; %cl = Client::getNext(%cl))
  614.       {
  615.          %cl.notready = "";
  616.          %cl.notreadyCount = "";
  617.          bottomprint(%cl, "", 0);
  618.       }
  619.    }
  620.    Server::Countdown(30);
  621. }
  622.  
  623. function Game::CheckTourneyMatchStart()
  624. {
  625.    if($CountdownStarted || $matchStarted)
  626.       return;
  627.    
  628.    // loop through all the clients and see if any are still notready
  629.    %playerCount = 0;
  630.    %notReadyCount = 0;
  631.  
  632.    for(%cl = Client::getFirst(); %cl != -1; %cl = Client::getNext(%cl))
  633.    {
  634.       if(%cl.observerMode == "pickingTeam")
  635.       {
  636.          %notReady[%notReadyCount] = %cl;
  637.          %notReadyCount++;
  638.       }   
  639.       else if(%cl.observerMode == "pregame")
  640.       {
  641.          if(%cl.notready)
  642.          {
  643.             %notReady[%notReadyCount] = %cl;
  644.             %notReadyCount++;
  645.          }
  646.          else
  647.             %playerCount++;
  648.       }
  649.    }
  650.    if(%notReadyCount)
  651.    {
  652.       if(%notReadyCount == 1)
  653.          MessageAll(0, Client::getName(%notReady[0]) @ " is holding things up!");
  654.       else if(%notReadyCount < 4)
  655.       {
  656.          for(%i = 0; %i < %notReadyCount - 2; %i++)
  657.             %str = Client::getName(%notReady[%i]) @ ", " @ %str;
  658.  
  659.          %str = %str @ Client::getName(%notReady[%i]) @ " and " @ Client::getName(%notReady[%i+1]) 
  660.                      @ " are holding things up!";
  661.          MessageAll(0, %str);
  662.       }
  663.       return;
  664.    }
  665.  
  666.    if(%playerCount != 0)
  667.    {
  668.       for(%cl = Client::getFirst(); %cl != -1; %cl = Client::getNext(%cl))
  669.       {
  670.          %cl.notready = "";
  671.          %cl.notreadyCount = "";
  672.          bottomprint(%cl, "", 0);
  673.       }
  674.       Server::Countdown(30);
  675.    }
  676. }
  677.  
  678.  
  679. function Game::checkTimeLimit()
  680. {
  681.    // if no timeLimit set or timeLimit set to 0,
  682.    // just reschedule the check for a minute hence
  683.    $timeLimitReached = false;
  684.  
  685.    if(!$Server::timeLimit)
  686.    {
  687.       schedule("Game::checkTimeLimit();", 60);
  688.       return;
  689.    }
  690.    %curTimeLeft = ($Server::timeLimit * 60) + $missionStartTime - getSimTime();
  691.    if(%curTimeLeft <= 0 && $matchStarted)
  692.    {
  693.       echo("GAME: Timelimit reached.");
  694.       $timeLimitReached = true;
  695.       Server::nextMission();
  696.    }
  697.    else
  698.    {
  699.       schedule("Game::checkTimeLimit();", 20);
  700.       UpdateClientTimes(%curTimeLeft);
  701.    }
  702. }
  703.  
  704. function Game::resetScores(%client)
  705. {
  706.     if(%client == "") {
  707.        for(%cl = Client::getFirst(); %cl != -1; %cl = Client::getNext(%cl)) {
  708.           %cl.scoreKills = 0;
  709.           %cl.scoreDeaths = 0;
  710.             %cl.ratio = 0;
  711.           %cl.score = 0;
  712.         }
  713.     }
  714.     else {
  715.       %client.scoreKills = 0;
  716.          %client.scoreDeaths = 0;
  717.         %client.ratio = 0;
  718.          %client.score = 0;
  719.     }
  720. }
  721.  
  722. function remoteSetArmor(%player, %armorType)
  723. {
  724.     if ($ServerCheats) {
  725.         checkMax(Player::getClient(%player),%armorType);
  726.        Player::setArmor(%player, %armorType);
  727.     }
  728.     else if($TestCheats) {
  729.        Player::setArmor(%player, %armorType);
  730.     }
  731. }
  732.  
  733.  
  734. function Game::onPlayerConnected(%playerId)
  735. {
  736.    %playerId.scoreKills = 0;
  737.    %playerId.scoreDeaths = 0;
  738.     %playerId.score = 0;
  739.    %playerId.justConnected = true;
  740.    $menuMode[%playerId] = "None";
  741.    Game::refreshClientScore(%playerId);
  742. }
  743.  
  744. function Game::assignClientTeam(%playerId)
  745. {
  746.    if($teamplay)
  747.    {
  748.       %name = Client::getName(%playerId);
  749.       %numTeams = getNumTeams();
  750.       if($teamPreset[%name] != "")
  751.       {
  752.          if($teamPreset[%name] < %numTeams)
  753.          {
  754.             GameBase::setTeam(%playerId, $teamPreset[%name]);
  755.             echo(Client::getName(%playerId), " was preset to team ", $teamPreset[%name]);
  756.             return;
  757.          }            
  758.       }
  759.       %numPlayers = getNumClients();
  760.       for(%i = 0; %i < %numTeams; %i = %i + 1)
  761.          %numTeamPlayers[%i] = 0;
  762.  
  763.       for(%i = 0; %i < %numPlayers; %i = %i + 1)
  764.       {
  765.          %pl = getClientByIndex(%i);
  766.          if(%pl != %playerId)
  767.          {
  768.             %team = Client::getTeam(%pl);
  769.             %numTeamPlayers[%team] = %numTeamPlayers[%team] + 1;
  770.          }
  771.       }
  772.       %leastPlayers = %numTeamPlayers[0];
  773.       %leastTeam = 0;
  774.       for(%i = 1; %i < %numTeams; %i = %i + 1)
  775.       {
  776.          if( (%numTeamPlayers[%i] < %leastPlayers) || 
  777.             ( (%numTeamPlayers[%i] == %leastPlayers) && 
  778.             ($teamScore[%i] < $teamScore[%leastTeam] ) ))
  779.          {
  780.             %leastTeam = %i;
  781.             %leastPlayers = %numTeamPlayers;
  782.          }
  783.       }
  784.       GameBase::setTeam(%playerId, %leastTeam);
  785.       echo(Client::getName(%playerId), " was automatically assigned to team ", %leastTeam);
  786.    }
  787.    else
  788.    {
  789.       GameBase::setTeam(%playerId, 0);
  790.    }
  791. }
  792.  
  793. function Client::onKilled(%playerId, %killerId, %damageType)
  794. {
  795.    echo("GAME: kill " @ %killerId @ " " @ %playerId @ " " @ %damageType);
  796.    %playerId.guiLock = true;
  797.    Client::setGuiMode(%playerId, $GuiModePlay);
  798.     if(!String::ICompare(Client::getGender(%playerId), "Male"))
  799.    {
  800.       %playerGender = "his";
  801.    }
  802.     else
  803.     {
  804.         %playerGender = "her";
  805.     }
  806.     %ridx = floor(getRandom() * ($numDeathMsgs - 0.01));
  807.     %victimName = Client::getName(%playerId);
  808.  
  809.  
  810.    if(!%killerId)
  811.    {
  812.       messageAll(0, strcat(%victimName, " dies."), $DeathMessageMask);
  813.       %playerId.scoreDeaths++;
  814.   }
  815.    else if(%killerId == %playerId)
  816.    {
  817.       %oopsMsg = sprintf($deathMsg[-2, %ridx], %victimName, %playerGender);
  818.       messageAll(0, %oopsMsg, $DeathMessageMask);
  819.       %playerId.scoreDeaths++;
  820.       %playerId.score--;
  821.       Game::refreshClientScore(%playerId);
  822.    }
  823.    else
  824.    {
  825.         if(!String::ICompare(Client::getGender(%killerId), "Male"))
  826.         {
  827.             %killerGender = "his";
  828.         }
  829.         else
  830.         {
  831.             %killerGender = "her";
  832.         }
  833.       if($teamplay && (Client::getTeam(%killerId) == Client::getTeam(%playerId)))
  834.       {
  835.         if(%damageType != $MineDamageType) 
  836.             messageAll(0, strcat(Client::getName(%killerId), 
  837.                " mows down ", %killerGender, " teammate, ", %victimName), $DeathMessageMask);
  838.         else 
  839.              messageAll(0, strcat(Client::getName(%killerId), 
  840.                 " killed ", %killerGender, " teammate, ", %victimName ," with a mine."), $DeathMessageMask);
  841.          %killerId.scoreDeaths++;
  842.        %killerId.score--;
  843.        Game::refreshClientScore(%killerId);
  844.       }
  845.       else
  846.       {
  847.          %obitMsg = sprintf($deathMsg[%damageType, %ridx], Client::getName(%killerId),
  848.            %victimName, %killerGender, %playerGender);
  849.          messageAll(0, %obitMsg, $DeathMessageMask);
  850.          %killerId.scoreKills++;
  851.          %playerId.scoreDeaths++;  // test play mode
  852.          %killerId.score++;
  853.          Game::refreshClientScore(%killerId);
  854.          Game::refreshClientScore(%playerId);
  855.       }
  856.    }
  857.    Game::clientKilled(%playerId, %killerId);
  858. }
  859.  
  860. function Game::clientKilled(%playerId, %killerId)
  861. {
  862.    // do nothing
  863. }
  864.  
  865. function Client::leaveGame(%clientId)
  866. {
  867.    // do nothing
  868. }
  869.  
  870. function Player::enterMissionArea(%player)
  871. {
  872.    echo("Player " @ %player @ " entered the mission area.");
  873. }
  874.  
  875. function Player::leaveMissionArea(%player)
  876. {
  877.    echo("Player " @ %player @ " left the mission area.");
  878. }
  879.  
  880. function GameBase::getHeatFactor(%this)
  881. {
  882.    return 0.0;
  883. }
  884.  
  885.